package com.caijg.domain.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 返回的消息体。result的内容是返回中的data中的内容
 * 前端接收到的返回体如下
 * {
 *     status:xxx
 *     data:{
 *         status:xxx
 *         msg:xxx
 *         data:{xxx}
 *     }
 * }
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    private Integer status;
    private String msg;
    private Object data;

    public static Result success() {
        return new Result(200, "success", null);
    }

    public static Result success(Object data) {
        return new Result(200, "success", data);
    }

    public static Result error(int code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error(String msg) {
        return error(500, msg);
    }

    // 自定义返回
    public static Result build(Integer code, String msg, Object data) {
        Result result = new Result();
        result.setStatus(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }
}